﻿using HardcoreGame.Common.Abstract;
using HardcoreGame.Common.Cores.Seasons;
using HardcoreGame.Common.Systems;
using Terraria;
using Terraria.Enums;
using Terraria.ID;
using Terraria.ModLoader;
namespace HardcoreGame.Common.GlobalTiles
{
    public class SeasonFruitGlobalTile : GlobalTile
    {
        public float DropChance = 0.1f;
        public override void PreShakeTree(int x, int y, TreeTypes treeType)
        {
            SeasonSystem seasonSystem = ModContent.GetInstance<SeasonSystem>();
            Season currentSeason = seasonSystem.currentSeason;
            #region 森林树
            if (treeType == TreeTypes.Forest)
            {
                // 苹果
                if (currentSeason is Winter || currentSeason is Summer || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Apple);
                }
                if (currentSeason is Autumn)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Apple);
                    }
                }
                // 杏
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Apricot);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Apricot);
                    }
                }
                // 葡萄柚
                if (currentSeason is Spring || currentSeason is Autumn || currentSeason is Summer)
                {
                    NPCLoader.blockLoot.Add(ItemID.Grapefruit);
                }
                if (currentSeason is Winter)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Grapefruit);
                    }
                }
                // 柠檬
                if (currentSeason is Winter || currentSeason is Spring || currentSeason is Summer)
                {
                    NPCLoader.blockLoot.Add(ItemID.Lemon);
                }
                if (currentSeason is Autumn)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Lemon);
                    }
                }
                // 桃子
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Peach);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Peach);
                    }
                }
            }
            #endregion
            #region 针叶树
            if (treeType == TreeTypes.Forest)
            {
                // 樱桃
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Cherry);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Cherry);
                    }
                }
                // 李子
                if (currentSeason is Winter || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Plum);
                }
                if (currentSeason is Autumn || currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Plum);
                    }
                }
            }
            #endregion
            #region 乌木树
            if (treeType == TreeTypes.Corrupt)
            {
                // 黑醋栗
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.BlackCurrant);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.BlackCurrant);
                    }
                }
                // 接骨木果
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Elderberry);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Elderberry);
                    }
                }
            }
            #endregion
            #region 乌木棕榈树
            if (treeType == TreeTypes.PalmCorrupt)
            {
                // 黑醋栗
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.BlackCurrant);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.BlackCurrant);
                    }
                }
                // 接骨木果
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Elderberry);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Elderberry);
                    }
                } // 香蕉
                if (Main.rand.NextFloat() < DropChance)
                {
                    Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Banana);
                }// 椰子
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Coconut);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Coconut);
                    }
                }
            }
            #endregion
            #region 暗影木树
            if (treeType == TreeTypes.Crimson)
            {
                // 血橙
                if (currentSeason is Summer || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.BloodOrange);
                }
                if (currentSeason is Winter)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.BloodOrange);
                    }
                }
                // 红毛丹
                if (currentSeason is Winter || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Rambutan);
                }
                if (currentSeason is Summer || currentSeason is Autumn)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Rambutan);
                    }
                }
            }
            #endregion
            #region 暗影木棕榈树
            if (treeType == TreeTypes.PalmCrimson)
            {
                // 血橙
                if (currentSeason is Summer || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.BloodOrange);
                }
                if (currentSeason is Winter && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.BloodOrange);
                    }
                }
                // 红毛丹
                if (currentSeason is Winter || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Rambutan);
                }
                if (currentSeason is Summer || currentSeason is Autumn && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Rambutan);
                    }
                }
                // 香蕉
                if (Main.rand.NextFloat() < DropChance)
                {
                    Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Banana);
                }// 椰子
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Coconut);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Coconut);
                    }
                }
            }
            #endregion
            #region 红木树
            if (treeType == TreeTypes.Jungle)
            {
                // 芒果
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Mango);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Mango);
                    }
                }
                // 菠萝
                if (currentSeason is Summer || currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Pineapple);
                    }
                }
            }
            #endregion
            #region 棕榈树
            if (treeType == TreeTypes.Palm)
            {
                // 香蕉
                if (Main.rand.NextFloat() < DropChance)
                {
                    Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Banana);
                }
                // 椰子
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Coconut);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Coconut);
                    }
                }
            }
            #endregion
            #region 珍珠木树
            if (treeType == TreeTypes.Hallowed)
            {
                // 火龙果
                if (currentSeason is Winter)
                {
                    NPCLoader.blockLoot.Add(ItemID.Dragonfruit);
                }
                if (currentSeason is Summer || currentSeason is Autumn || currentSeason is Spring)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Dragonfruit);
                    }
                }
                // 杨桃
                if (currentSeason is Winter || currentSeason is Summer || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Starfruit);
                }
                if (currentSeason is Autumn)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Starfruit);
                    }
                }
            }
            #endregion
            #region 珍珠木棕榈树
            if (treeType == TreeTypes.PalmHallowed)
            {
                // 火龙果
                if (currentSeason is Winter)
                {
                    NPCLoader.blockLoot.Add(ItemID.Dragonfruit);
                }
                if (currentSeason is Summer || currentSeason is Autumn || currentSeason is Spring && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Dragonfruit);
                    }
                } // 香蕉
                if (Main.rand.NextFloat() < DropChance)
                {
                    Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Banana);
                }
                // 椰子
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Coconut);
                }
                if (currentSeason is Summer && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Coconut);
                    }
                }
                // 杨桃
                if (currentSeason is Winter || currentSeason is Summer || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Starfruit);
                }
                if (currentSeason is Autumn && Main.LocalPlayer.ZoneBeach)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Starfruit);
                    }
                }
            }
            #endregion
            #region 灰烬树
            if (treeType == TreeTypes.Ash)
            {
                // 石榴
                if (currentSeason is Winter || currentSeason is Summer || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.Pomegranate);
                }
                if (currentSeason is Autumn)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.Pomegranate);
                    }
                }
                // 辣椒
                if (currentSeason is Winter || currentSeason is Autumn || currentSeason is Spring)
                {
                    NPCLoader.blockLoot.Add(ItemID.SpicyPepper);
                }
                if (currentSeason is Summer)
                {
                    if (Main.rand.NextFloat() < DropChance)
                    {
                        Item.NewItem(WorldGen.GetItemSource_FromTreeShake(x, y), x * 16, y * 16, 16, 16, ItemID.SpicyPepper);
                    }
                }
            }
            #endregion
        }
    }
}
